package cn.finedo.controller;

import cn.finedo.common.NonUtil;
import cn.finedo.common.ReturnValueDomain;
import cn.finedo.dto.DynamicRequestRouterDto;
import cn.finedo.dto.ModelCallDto;
import cn.finedo.dto.OpticalSplitDto;
import cn.finedo.service.DynamicRequestRouterService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api/aiplatform")
@Scope("singleton")
public class DynamicRequestRouterController {

    @Autowired
    private DynamicRequestRouterService service;

    @ResponseBody
    @RequestMapping({"/jt"})
    public ReturnValueDomain<DynamicRequestRouterDto> jtDynamicRequestRouter(@RequestBody DynamicRequestRouterDto dto) {
        ReturnValueDomain<DynamicRequestRouterDto> ret = new ReturnValueDomain<>();
        if (NonUtil.isNon(dto.getRequestMsg())) {
            return ret.setFail("缺少必要参数");
        }
        return service.dynamicRequestRouter(dto);
    }

    @ResponseBody
    @RequestMapping({"/third-party"})
    public ReturnValueDomain<DynamicRequestRouterDto> thirdDynamicRequestRouter(@RequestBody DynamicRequestRouterDto dto) {
        ReturnValueDomain<DynamicRequestRouterDto> ret = new ReturnValueDomain<>();
        if (NonUtil.isNon(dto.getRequestMsg())) {
            return ret.setFail("缺少必要参数");
        }
        return service.dynamicRequestRouter(dto);
    }

    @ResponseBody
    @RequestMapping({"/modelservice"})
    public ReturnValueDomain<ModelCallDto> modelServiceRouter(@RequestBody ModelCallDto dto) {
        ReturnValueDomain<ModelCallDto> ret = new ReturnValueDomain<>();
        if (NonUtil.isNon(dto) || NonUtil.isNon(dto.getDetectimg()) || NonUtil.isNon(dto.getProject())) {
            return ret.setFail("缺少必要参数");
        }
        return service.modelServiceCall(dto);
    }

    @ResponseBody
    @RequestMapping({"/opticalsplit"})
    public JSONObject OpticalSplit(@RequestBody OpticalSplitDto dto) {
        if (NonUtil.isNon(dto) || NonUtil.isNon(dto.getFileName()) || NonUtil.isNon(dto.getImageBase64())) {
            return service.createErrorJson("缺少必要参数");
        }
        return service.OpticalSplit(dto);
    }
}
